// ========================================================================= //

// includes
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "string.h"
#include "limits.h"
#include "float.h"



#define JOTAI_NUM_RANDS_ 25

const unsigned rand_primes[JOTAI_NUM_RANDS_] = {179, 103, 479, 647, 229, 37, 271, 557, 263, 607, 18743, 50359, 21929, 48757, 98179, 12907, 52937, 64579, 49957, 52567, 507163, 149939, 412157, 680861, 757751};

int next_i() {
  int counter = 0;
  return rand_primes[(++counter)%JOTAI_NUM_RANDS_];
}

float next_f() {
  int counter = 0;
  return rand_primes[(++counter)%JOTAI_NUM_RANDS_] / 757751.0F;
} 


// Usage menu
void usage() {
    printf("%s", "Usage:\n\
    prog [ARGS]\n\
\nARGS:\n\
       0            int-bounds\n\
       1            big-arr\n\
       2            big-arr-10x\n\
\n\
");

}


// ------------------------------------------------------------------------- //

#define NULL ((void*)0)
typedef unsigned long size_t;  // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__;  // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef  int u8 ;
typedef  int u32 ;
typedef  int u16 ;

/* Variables and functions */

__attribute__((used)) static u8 si1145_compress(u16 x)
{
	u32 exponent = 0;
	u32 significand = 0;
	u32 tmp = x;

	if (x == 0x0000)
		return 0x00;
	if (x == 0x0001)
		return 0x08;

	while (1) {
		tmp >>= 1;
		exponent += 1;
		if (tmp == 1)
			break;
	}

	if (exponent < 5) {
		significand = x << (4 - exponent);
		return (exponent << 4) | (significand & 0xF);
	}

	significand = x >> (exponent - 5);
	if (significand & 1) {
		significand += 2;
		if (significand & 0x0040) {
			exponent += 1;
			significand >>= 1;
		}
	}

	return (exponent << 4) | ((significand >> 1) & 0xF);
}

// ------------------------------------------------------------------------- //

int main(int argc, char *argv[]) {

    if (argc != 2) {
        usage();
        return 1;
    }

    int opt = atoi(argv[1]);
    switch(opt) {


    // int-bounds
    case 0:
    {
          // static_instructions_O0 : 43
          // dynamic_instructions_O0 : 87
          // ------------------------------- 
          // static_instructions_O1 : 33
          // dynamic_instructions_O1 : 58
          // ------------------------------- 
          // static_instructions_O2 : 33
          // dynamic_instructions_O2 : 58
          // ------------------------------- 
          // static_instructions_O3 : 33
          // dynamic_instructions_O3 : 58
          // ------------------------------- 
          // static_instructions_Ofast : 33
          // dynamic_instructions_Ofast : 58
          // ------------------------------- 
          // static_instructions_Os : 32
          // dynamic_instructions_Os : 57
          // ------------------------------- 
          // static_instructions_Oz : 32
          // dynamic_instructions_Oz : 57
          // ------------------------------- 

          int x = 100;
        
          int benchRet = si1145_compress(x);
          printf("%d\n", benchRet); 
        
        break;
    }


    // big-arr
    case 1:
    {
          // static_instructions_O0 : 57
          // dynamic_instructions_O0 : 110
          // ------------------------------- 
          // static_instructions_O1 : 39
          // dynamic_instructions_O1 : 69
          // ------------------------------- 
          // static_instructions_O2 : 39
          // dynamic_instructions_O2 : 69
          // ------------------------------- 
          // static_instructions_O3 : 39
          // dynamic_instructions_O3 : 69
          // ------------------------------- 
          // static_instructions_Ofast : 39
          // dynamic_instructions_Ofast : 69
          // ------------------------------- 
          // static_instructions_Os : 38
          // dynamic_instructions_Os : 68
          // ------------------------------- 
          // static_instructions_Oz : 38
          // dynamic_instructions_Oz : 68
          // ------------------------------- 

          int x = 255;
        
          int benchRet = si1145_compress(x);
          printf("%d\n", benchRet); 
        
        break;
    }


    // big-arr-10x
    case 2:
    {
          // static_instructions_O0 : 39
          // dynamic_instructions_O0 : 56
          // ------------------------------- 
          // static_instructions_O1 : 27
          // dynamic_instructions_O1 : 37
          // ------------------------------- 
          // static_instructions_O2 : 27
          // dynamic_instructions_O2 : 37
          // ------------------------------- 
          // static_instructions_O3 : 27
          // dynamic_instructions_O3 : 37
          // ------------------------------- 
          // static_instructions_Ofast : 27
          // dynamic_instructions_Ofast : 37
          // ------------------------------- 
          // static_instructions_Os : 27
          // dynamic_instructions_Os : 37
          // ------------------------------- 
          // static_instructions_Oz : 27
          // dynamic_instructions_Oz : 37
          // ------------------------------- 

          int x = 10;
        
          int benchRet = si1145_compress(x);
          printf("%d\n", benchRet); 
        
        break;
    }

    default:
        usage();
        break;

    }

    return 0;
}
